package cn.e4j.modular.api.controller;

import cn.digiwin.wx.utils.WeixinHandler;
import cn.e4j.core.dto.Dtos;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.util.AppCxt;
import cn.e4j.core.util.DateUtils;
import cn.e4j.core.util.InvokeUtil;
import cn.e4j.core.util.ToolUtil;
import cn.e4j.modular.api.service.GwaService;
import cn.e4j.modular.api.service.Gwat100Service;
import cn.e4j.modular.api.util.CommonUtils;
import cn.e4j.modular.api.util.ControllerSupport;
import cn.e4j.modular.crm.entity.*;
import cn.e4j.modular.system.entity.SysUser;
import cn.e4j.modular.system.service.impl.SystemServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 意向商机询单 控制类
 * Created by shixc on 2018/4/28.
 */
@RestController
@RequestMapping("api/wx/gwat100")
public class Gwat100Controller extends ControllerSupport {

    @Autowired
    Gwat100Service gwat100Service;

    @Autowired
    SystemServiceImpl systemService;

    @Autowired
    GwaService gwaService;



    /**
     * 获取产品分类
     *
     * @return
     */
    @RequestMapping(value = "getGwahData")
    public ResponseData getGwahData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwahData(inDto);
        return SUCCESS(list);
    }

    /**
     * 获取产品分类图片
     *
     * @return
     */
    @RequestMapping(value = "getGwamData")
    public ResponseData getGwamData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwamData(inDto);
        return SUCCESS(list);
    }

    /**
     * 获取产品系列
     *
     * @return
     */
    @RequestMapping(value = "getGwaoData")
    public ResponseData getGwaoData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwaoData(inDto);
        return SUCCESS(list);
    }

    /**
     * 获取产品信息
     *
     * @return
     */
    @RequestMapping(value = "getGwamPage")
    public ResponseData getGwamPage(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwamPage(wapper.getPage(),inDto);

        return SUCCESS(list);
    }

    /**
     * 获取产品详细信息
     *
     * @return
     */
    @RequestMapping(value = "getGwamDetail")
    public ResponseData getGwamDetail(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwamDetail(inDto);
        return SUCCESS(list);
    }

    /**
     * 获取产品介绍
     *
     * @return
     */
    @RequestMapping(value = "getGwamOther")
    public ResponseData getGwamOther(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        inDto.put("GWAMENT", inDto.getString("ENT"));
        return SUCCESS(gwat100Service.getGwamOther(inDto));
    }

    /**
     * 获取配置表信息
     *
     * @return
     */
    @RequestMapping(value = "getGwax")
    public ResponseData getGwax(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwax(inDto);
        return SUCCESS(list);
    }

    /**
     * 获取产品属性特征信息
     *
     * @return
     */
    @RequestMapping(value = "getGwan")
    public ResponseData getGwan(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = null;
        try {
            list = gwat100Service.getGwan(inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(list);
    }

    /**
     * 获取产品属性特征值信息
     *
     * @return
     */
    @RequestMapping(value = "getGwaj")
    public ResponseData getGwaj(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwaj(inDto);
        return SUCCESS(list);
    }

    /**
     * 获取产品评价信息
     *
     * @return
     */
    @RequestMapping(value = "getGwcw")
    public ResponseData getGwcw(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> sortList = new ArrayList<>();
        //排序
//        Dto sort = Dtos.newDto();
//        sort.put("property", "gwcwdocdate");
//        sort.put("direction", "desc");
//        sortList.add(sort);
//        inDto.put("sort", AppJson.toGridJson(sortList));
        List<Dto> list = new ArrayList<>();
        if (inDto.getString("status").equals("1")) {   //只查子料号的评论子料号
            list = gwat100Service.getGwcw(wapper.getPage(),inDto);
        } else {
            list = gwat100Service.getGwcw1(inDto);
        }
        return SUCCESS(list);
    }

    /**
     * 获取产品评价数量
     *
     * @return
     */
    @RequestMapping(value = "getGwcwCount")
    public ResponseData getGwcwCount(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto outDto = new Dto();
        Dto plist = Dtos.newDto();
        if (inDto.getString("status").equals("1")) {   //只查子料号的评论子料号
            plist = gwat100Service.getGwcwCount(inDto);
        } else {
            plist = gwat100Service.getGwcwCount1(inDto);
        }
        outDto.put("count", plist);
        return SUCCESS(outDto);
    }

    /**
     * 获取暂存产品信息
     *
     * @return
     */
    @RequestMapping(value = "getGwcmDataPage")
    public ResponseData getGwcmDataPage(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser currentUser = wapper.getSysUser();
        inDto.put("GWCM008", currentUser.getACCOUNT());
        List<Dto> list = gwat100Service.getGwcmDataPage(inDto);
        return SUCCESS(list);
    }

    /**
     * 新建客户时 检查客户手机号是否存在
     *
     * @return
     */
    @RequestMapping(value = "checkCustomerPhone")
    public ResponseData checkCustomerPhone(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto outDto = new Dto();
        try {
            inDto.put("GWAKENT", inDto.getString("ENT"));
            inDto.put("GWAKACTI", "Y");
            outDto.put("count", gwat100Service.checkCustomerPhone(inDto));
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(outDto);
    }
//
    /**
     * 新建客户时 检查客户名称是否存在
     *
     * @return
     */
    @RequestMapping(value = "checkCustomerName")
    public ResponseData checkCustomerName(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        Dto outDto = new Dto();
        try {
            inDto.put("GWAKLENT", inDto.getString("ENT"));
            outDto.put("count", gwat100Service.checkCustomerName(inDto));
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(outDto);
    }

    /**
     * 获取客户信息
     *
     * @return
     */
    @RequestMapping(value = "getGwakPage")
    public ResponseData getGwakPage(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser currentUser = wapper.getSysUser();
        inDto.put("GWAK019", currentUser.getACCOUNT());
        List<Dto> list = gwat100Service.getGwakPage(inDto);
        return SUCCESS(list);
    }
//
    /**
     * 保存客户信息
     *
     * @return
     */
    @RequestMapping(value = "saveCustomer")
    public ResponseData saveCustomer(@DtoParam DtoWapper wapper) {
        Dto indto = wapper.getDto();
        GwaklT gwakl_tPO = JSON.parseObject(JSON.toJSONString(indto), GwaklT.class);
        GwakT  gwak_tPO = JSON.parseObject(JSON.toJSONString(indto), GwakT.class);
        GwalT gwal_tPO = JSON.parseObject(JSON.toJSONString(indto), GwalT.class);
        SysUser currentUser = wapper.getSysUser();

        try {

            gwak_tPO.setGWAKENT(currentUser.getDBC());
            gwak_tPO.setGWAK002("1");// 1.客户、2.厂商、3.两者
            gwak_tPO.setGWAK006("1");//1.最终客户、2.经销商、3.内部法人、4.其他类
//            String sys_currency = AppCxt.getParam("SYS_CURRENCY");
//            gwak_tPO.setGWAK008(sys_currency==null?" ":sys_currency);
            gwak_tPO.setGWAK009("*");//客户分类
            gwak_tPO.setGWAK010("*"); //客户渠道
            String tax_type = AppCxt.getParam("TAX_TYPE");
            gwak_tPO.setGWAK012(tax_type == null?" ":tax_type);
            gwak_tPO.setGWAK019(currentUser.getACCOUNT());
            gwak_tPO.setGWAK020("ASIA");
            gwak_tPO.setGWAK021("CN");


            // add by wenchuan.li 2018/10/26 13:31
//            Dto sys002Dto = Dtos.newDto();
//            sys002Dto.put("ORG_ID", currentUser.getORG_ID());
//            Dto sys002 = systemService.getSys002(sys002Dto);
//            gwak_tPO.setGWAKPLANT(sys002.getString("ID"));//法人
            gwak_tPO.setGWAK056(BigDecimal.ONE);//折扣率
            String type = AppCxt.getParam("CHANGE_RATE_TYPE_");
            gwak_tPO.setGWAK057(type == null?" ":type);
            gwak_tPO.setGWAKACTI("Y");


            gwakl_tPO.setGWAKLENT(currentUser.getDBC());
            gwakl_tPO.setGWAKL004(gwakl_tPO.getGWAKL003());

            if(gwakl_tPO.getGWAKL003().length() >= 6){
                gwakl_tPO.setGWAKL003(gwakl_tPO.getGWAKL003().substring(0,6));
            }else{
                gwakl_tPO.setGWAKL003(gwakl_tPO.getGWAKL003());
            }
            gwakl_tPO.setGWAKL002("2");

            Dto inDto1 = Dtos.newDto();
            inDto1.put("GWAKENT", indto.getString("ENT"));
            inDto1.put("GWAK001_S",DateUtils.getDate("yyMMdd"));
            Dto dto = gwat100Service.getGwak001(inDto1);

            if (dto != null && dto.containsKey("GWAK001")
                    && ToolUtil.isNotEmpty(dto.getString("GWAK001"))
                    && dto.getString("GWAK001").length() == 9) {
                String gwak001 = dto.getString("GWAK001");
                int no = Integer.parseInt(gwak001) + 1;
                String gwak001New = (no > 99999999 ? "" : "0") + String.valueOf(no);
                gwak_tPO.setGWAK001(gwak001New);
                gwakl_tPO.setGWAKL001(gwak001New);
                gwakl_tPO.setGWAKL005(gwak001New);
            } else {
                gwak_tPO.setGWAK001(inDto1.getString("GWAK001_S") + "001");
                gwakl_tPO.setGWAKL001(inDto1.getString("GWAK001_S") + "001");
                gwakl_tPO.setGWAKL005(inDto1.getString("GWAK001_S") + "001");
            }
            gwal_tPO.setGWALUSER(currentUser.getID());
            gwal_tPO.setGWALMODU(currentUser.getID());
            gwal_tPO.setGWALORIU(currentUser.getID());
            gwal_tPO.setGWALGRUP(currentUser.getORG_ID());
            gwal_tPO.setGWALORIG(currentUser.getORG_ID());
            gwal_tPO.setGWALDATE(LocalDate.now());
            gwal_tPO.setGWALTIME(DateUtils.getTime());
            gwal_tPO.setGWALENT(currentUser.getDBC());
            gwal_tPO.setGWAL001(gwak_tPO.getGWAK001());

            Dto d = new Dto();
            d.put("GWAL001", gwak_tPO.getGWAK001());
            d.put("GWALENT", indto.getString("ENT"));
            gwal_tPO.setGWAL002(gwaService.getGwa002(d));

            gwal_tPO.setGWAL003("Y");
            gwal_tPO.setGWAL010(gwak_tPO.getGWAK020());
            gwal_tPO.setGWAL011(gwak_tPO.getGWAK021());
            gwal_tPO.setGWAL012(gwak_tPO.getGWAK022());
            gwal_tPO.setGWAL013(gwak_tPO.getGWAK023());
            gwal_tPO.setGWAL014(gwak_tPO.getGWAK024());
            gwal_tPO.setGWAL015(gwak_tPO.getGWAK025());
            gwal_tPO.setGWAL016(ToolUtil.isNotEmpty(gwak_tPO.getGWAK026()) ? gwak_tPO.getGWAK026() : "*");
            gwal_tPO.setGWAL017(ToolUtil.isNotEmpty(gwak_tPO.getGWAK027()) ? gwak_tPO.getGWAK027() : "*");
            gwal_tPO.setGWAL018(ToolUtil.isNotEmpty(gwak_tPO.getGWAK028()) ? gwak_tPO.getGWAK028() : "*");
            gwal_tPO.setGWAL019(ToolUtil.isNotEmpty(gwak_tPO.getGWAK029()) ? gwak_tPO.getGWAK029() : "*");
            gwal_tPO.setGWAL020(ToolUtil.isNotEmpty(gwak_tPO.getGWAK030()) ? gwak_tPO.getGWAK030() : "*");
            gwal_tPO.setGWAL021(gwak_tPO.getGWAK031());
            gwal_tPO.setGWALACTI("Y");

            gwat100Service.saveCustomer(gwak_tPO, gwakl_tPO, gwal_tPO);
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("服务器出小差了");
        }

        return SUCCESS;
    }

    /**
     * 获取线人信息
     * <p>
     * gwak018线人电话 gwak017线人姓名
     *
     * @return
     */
    @RequestMapping(value = "getGwak")
    public ResponseData getGwak(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwak(inDto);
        return SUCCESS(list);
    }

    /**
     * 暂存
     *
     * @return
     */
    @RequestMapping(value = "saveData")
    public ResponseData saveData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser currentUser = wapper.getSysUser();
        GwcmT gwcm_tPO = new GwcmT();
        List<GwcnT> gwcn_tPOs = new ArrayList<>();
        Dto outDto = new Dto();
        LocalDate now = LocalDate.now();
        try {
            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));
            gwcm_tPO = CommonUtils.toJavaClass(inJson,GwcmT.class);

            gwcm_tPO.setGWCMENT(currentUser.getDBC());
            //TEMP
            //gwcm_tPO.setGWCMDOCNO("QZSJ" + DateUtils.getDate("yyyyMMddHHmmssSSS"));
            gwcm_tPO.setGWCMDOCNO("TEMP" + DateUtils.getDate("yyyyMMddHHmmssSSS"));
            gwcm_tPO.setGWCMSEQ(BigDecimal.ONE);
            gwcm_tPO.setGWCMDOCDATE(now);
            //gwcm_tPO.setGWCM001(inJson.getString("GWCM001"));
            //gwcm_tPO.setGWCM002(inJson.getString("GWCM008")); // 销售单位
            //gwcm_tPO.setGWCM003(inJson.getBigDecimal("GWCM003"));
            //gwcm_tPO.setGWCM004(inJson.getBigDecimal("GWCM004"));
            gwcm_tPO.setGWCM005(inJson.getBigDecimal("GWCM003").multiply(inJson.getBigDecimal("GWCM004")));
            gwcm_tPO.setGWCM008(currentUser.getACCOUNT());
            gwcm_tPO.setGWCMDATE(now);
            gwcm_tPO.setGWCMACTI("N"); //未提交
            gwcm_tPO.setGWCMORIU(currentUser.getID());

            gwat100Service.saveData(gwcm_tPO, gwcn_tPOs);
            outDto.put("GWCMDOCNO", gwcm_tPO.getGWCMDOCNO());
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(outDto);
    }

    /**
     * 修改gwcm_t，gwcn_t
     *
     * @return
     */
    @RequestMapping(value = "updateData")
    public ResponseData updateData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        SysUser currentUser = wapper.getSysUser();
        List<GwcmT> gwcm_tPOs = new ArrayList<>();
        List<Dto> gwcn_tPOs = new ArrayList<>();
        LocalDate now = LocalDate.now();
        try {
            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));
            JSONArray orders = inJson.getJSONArray("orders");

            for (int i = 0, j = orders.size(); i < j; i++) {
                JSONObject item = orders.getJSONObject(i);
                GwcmT gwcm_tPO = new GwcmT();
                gwcm_tPO.setGWCMENT(currentUser.getDBC());
                gwcm_tPO.setGWCMDOCNO(item.getString("GWCMDOCNO"));
                gwcm_tPO.setGWCM001(item.getString("GWCM001"));
                gwcm_tPO.setGWCMSEQ(item.getBigDecimal("GWCMSEQ"));
                gwcm_tPO.setGWCM003(item.getBigDecimal("GWCM003"));
                gwcm_tPO.setGWCM004(item.getBigDecimal("GWCM004"));
                gwcm_tPO.setGWCM005(item.getBigDecimal("GWCM003").multiply(item.getBigDecimal("GWCM004")));
                gwcm_tPO.setGWCM050(item.getString("GWCM050"));
                gwcm_tPO.setGWCMDATE(now);
                gwcm_tPOs.add(gwcm_tPO);

            }
            gwat100Service.update(gwcm_tPOs, gwcn_tPOs);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS;
    }

    /**
     * 商品提交
     *
     * @return
     */
    @RequestMapping(value = "submitData")
    public ResponseData submitData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> gwcm_tPOs = new ArrayList<>();
        List<Dto> gwcn_tPOs = new ArrayList<>();
        SysUser currentUser = wapper.getSysUser();
        try {
            JSONObject inJson = JSONObject.parseObject(inDto.getString("obj"));
            JSONArray orders = inJson.getJSONArray("orders");
            String no = "QZSJ" + DateUtils.getDate("yyyyMMddHHmmssSSS");
            for (int i = 0, j = orders.size(); i < j; i++) {
                JSONObject item = orders.getJSONObject(i);
                Dto gwcm_tPO = Dtos.newDto();
                gwcm_tPO.put("GWCMENT", inDto.getString("ENT"));
                gwcm_tPO.put("GWCMDOCNO", item.getString("GWCMDOCNO"));
                gwcm_tPO.put("GWCMSEQ", item.getIntValue("GWCMSEQ"));
                gwcm_tPO.put("GWCMDOCNO1", no);
                gwcm_tPO.put("GWCMSEQ1", i + 1);
                gwcm_tPO.put("GWCM002", item.getString("GWCM002"));
                gwcm_tPO.put("GWCM003", item.getIntValue("GWCM003"));
                gwcm_tPO.put("GWCM010", inJson.getString("GWCM010"));
                gwcm_tPO.put("GWCM011", inJson.getString("GWCM011")); //客户编号
                //gwcm_tPO.put("GWCM012", new Date());
                gwcm_tPO.put("GWCM020", inJson.getString("GWCM020"));
                gwcm_tPO.put("GWCM021", inJson.getString("GWCM021"));
                gwcm_tPO.put("GWCM022", inJson.getString("GWCM022"));
                gwcm_tPO.put("GWCM023", inJson.getString("GWCM023"));
                gwcm_tPO.put("GWCM024", inJson.getString("GWCM024"));
                gwcm_tPO.put("GWCM025", inJson.getString("GWCM025"));
                gwcm_tPO.put("GWCM026", inJson.getString("GWCM026"));
                gwcm_tPO.put("GWCM027", inJson.getString("GWCM027"));
                gwcm_tPO.put("GWCM028", inJson.getString("GWCM028"));
                gwcm_tPO.put("GWCM009", inJson.getString("GWCM009"));
                gwcm_tPO.put("GWCM006", inJson.getString("GWCM006"));
                gwcm_tPO.put("GWCM007", inJson.getString("GWCM007"));
                gwcm_tPO.put("GWCM008", inJson.getString("GWCM008"));

                gwcm_tPO.put("GWCMACTI", "Y"); //已经提交
                gwcm_tPO.put("GWCMDOCDATE", new Date());
                gwcm_tPO.put("GWCMMODU", currentUser.getNAME());
                gwcm_tPO.put("GWCMDATE", new Date());
                gwcm_tPOs.add(gwcm_tPO);

                Dto gwcn_tPO = Dtos.newDto();
                gwcn_tPO.put("GWCNENT", inDto.getString("ENT"));
                gwcn_tPO.put("GWCNDOCNO", item.getString("GWCMDOCNO"));
                gwcn_tPO.put("GWCNSEQ2", item.getIntValue("GWCMSEQ"));
                gwcn_tPO.put("GWCNDOCNO_", no);
                gwcn_tPO.put("GWCNSEQ_", gwcm_tPO.getInteger("GWCMSEQ1"));
                gwcn_tPOs.add(gwcn_tPO);

            }
            gwat100Service.updateGoodsInfo(gwcm_tPOs, gwcn_tPOs);

            try {

                Dto gwaaDto = Dtos.newDto();
                gwaaDto.put("GWAAENT", inDto.getString("ENT"));
                gwaaDto.put("MMRE004", inJson.getString("GWCM026"));
                List<Dto> sysUser = gwat100Service.getGwaa(gwaaDto);
                WeixinHandler.sendMsg(sysUser,
                        String.format("有新的意向商机！客户名称[%s], 线人[%s], 线人手机号码[%s]",
                                inJson.getString("GWAKL004"),
                                inJson.getString("GWCM006"),
                                inJson.getString("GWCM007")
                        ));
            } catch (Exception e) {
                e.printStackTrace();
            }

        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS;
    }

    /**
     * 获取产品已经选择的特征信息
     *
     * @return
     */
    @RequestMapping(value = "getSelectedCharacteristic")
    public ResponseData getSelectedCharacteristic(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = null;
        try {
            inDto.put("GWCNENT", inDto.getString("ENT"));
            list = gwat100Service.getSelectedCharacteristic(inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(list);
    }

    /**
     * 获取评价信息
     *
     * @return
     */
    @RequestMapping(value = "getGwcwPage")
    public ResponseData getGwcwPage(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = gwat100Service.getGwcw(wapper.getPage(),inDto);
        return SUCCESS(list);
    }
    /**
     * 删除暂存
     *
     * @return
     */
    @RequestMapping("delete")
    public ResponseData delete(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        try {
            inDto.put("GWCMENT", inDto.getString("ENT"));
            GwcnT gwcnT = JSON.parseObject(JSON.toJSONString(inDto), GwcnT.class);
            GwcmT gwcmT = JSON.parseObject(JSON.toJSONString(inDto), GwcmT.class);
            gwat100Service.delete(gwcnT,gwcmT);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS;
    }

    //获取ERP营运据点
    @RequestMapping("getSite")
    public ResponseData getGWDE(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<GwdeT> list;
        try {
            QueryWrapper<GwdeT> wrapper = new QueryWrapper<>();
            wrapper.select("GWDE003","GWDE004");
            wrapper.eq("GWDEENT",inDto.getString("ENT"));
            wrapper.eq("GWDE002",inDto.getString("GWDE002"));
            wrapper.eq("GWDEACTI","Y");
            list = new GwdeT().selectList(wrapper);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(list);
    }

    //获取币别
    @RequestMapping("getCoin")
    public ResponseData getCoin(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> dtoList;
        try {
            dtoList = gwat100Service.getCoin(inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
        return SUCCESS(dtoList);
    }




}
